import java.util.Scanner;

public class Demo8 {
   public  static volatile boolean running =true;
    public static void main(String[] args) {

        Thread t=new Thread(()->{
            while (running){
                System.out.println("hello world");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //捕获终端异常后，退出循环
                    running=false;
                }
            }
            System.out.println("t线程退出");
        });
        t.start();
        Scanner scanner=new Scanner(System.in);
        System.out.println("输入0表示进程结束");
        int n=scanner.nextInt();
        if (n==0){
           running=false;
        }
    }
}
